package dshop;


import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.plugin.redis.RedisPlugin;
import com.jfinal.render.ViewType;
import com.jfinal.template.Engine;

import dshop.action.IndexAction;
import dshop.model.Account;
import dshop.model.AppSuperman;
import dshop.model.Area;
import dshop.model.Expert;
import dshop.model.Login;
import dshop.model.LoginHistory;
import dshop.model.Product;
import dshop.model.Project;
import dshop.model.StoreSetting;
import dshop.model.User;
import dshop.model.UserTag;
import dshop.model.activity.Activity;
import dshop.model.activity.ActivityComplain;
import dshop.model.commerce.Commerce;
import dshop.model.commerce.CommerceNews;
import dshop.model.commission.Commission;
import dshop.model.commission.CommissionDetail;
import dshop.model.company.Company;
import dshop.model.company.CompanyAuthentication;
import dshop.model.company.CompanyAuthenticationImage;
import dshop.model.company.CompanyNews;
import dshop.model.draw.DrawDetail;
import dshop.model.job.Job;
import dshop.model.job.JobCollect;
import dshop.model.job.JobComplain;
import dshop.model.member.MemberCompany;
import dshop.model.member.MemberGeneralInfo;
import dshop.model.member.MemberNews;
import dshop.model.member.MemberPermission;
import dshop.model.member.MemberVip;
import dshop.model.member.StoreCompany;
import dshop.model.member.SupperCompany;
import dshop.model.procurement.IndustryCategory;
import dshop.model.procurement.Procurement;
import dshop.model.news.News;
import dshop.model.procurement.ProcurementCollect;
import dshop.model.procurement.ProcurementComplain;
import dshop.model.push.PushNum;
import dshop.model.push.PushRecord;
import dshop.model.push.PushUser;
import dshop.model.push.UserPushAccount;
import dshop.route.AdminRoute;
import dshop.route.ApiRoute;

public class AppConfig extends JFinalConfig{

	public AppConfig() {
		loadPropertyFile("config.txt");
	}
	
	@Override
	public void configConstant(Constants me) 
	{
		boolean devMode = getPropertyToBoolean("devMode");
		me.setDevMode(devMode);
		me.setViewType(ViewType.JSP);
	}
	
	@Override
	public void afterJFinalStart()
	{
		AppConst.init();
	}
	
	@Override
	public void configHandler(Handlers arg0) {
	}

	@Override
	public void configInterceptor(Interceptors me) 
	{
	}

	@Override
	public void configEngine(Engine arg0) {}
	
	@Override
	public void configPlugin(Plugins me) 
	{
		//redis插件
		String redisCacheName = getProperty("redis_cache_name");
		String redisHost = getProperty("redis_host");
		int redisPort = getPropertyToInt("redis_port");
		int redisTimeOut = getPropertyToInt("redis_timeout");
		String redisPassword = getProperty("redis_password");
		RedisPlugin redis = new RedisPlugin(redisCacheName, redisHost, redisPort, redisTimeOut, redisPassword);
		me.add(redis);
		
//		#    url: jdbc:mysql://120.77.87.96:3306/diqwl_test_test?serverTimezone=GMT%2b8&useSSL=true&characterEncoding=UTF-8
//			#    username: root
//			#    password: diqwl2019@123
//			#    driver-class-name: com.mysql.cj.jdbc.Driver
		
		String jdbcUrl = "jdbc:mysql://120.77.87.96:3306/diqwl_test_test?serverTimezone=GMT%2b8&useSSL=true&characterEncoding=UTF-8";
		String jdbcUser = "root";
		String jdbcPass = "diqwl2019@123";		
//		String jdbcUrl = "jdbc:mysql://rm-wz9n6z21iw09gk8z4to.mysql.rds.aliyuncs.com:3306/diquan_db?serverTimezone=GMT%2b8&useSSL=true&characterEncoding=UTF-8";
//		String jdbcUser = "diqwl";
//		String jdbcPass = "diqwl2019@123";		
		
		DruidPlugin dp = new DruidPlugin(jdbcUrl, jdbcUser, jdbcPass);
		me.add(dp);
		
		ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
		me.add(arp);
		
		//表 - 实体 映射
		//后台账号
		arp.addMapping("user", User.class);
		
		//公司
		arp.addMapping("company", Company.class);
		arp.addMapping("company_authentication", "account_id", CompanyAuthentication.class);
//		arp.addMapping("company_authentication_image", CompanyAuthenticationImage.class);
//		arp.addMapping("company_news", CompanyNews.class);
		
		//会员
		arp.addMapping("member_general_info", "account_id", MemberGeneralInfo.class);
		arp.addMapping("member_company", MemberCompany.class);
		arp.addMapping("member_vip", "account_id", MemberVip.class);
		arp.addMapping("member_news", MemberNews.class);
		arp.addMapping("member_permission", "account_id", MemberPermission.class);
		arp.addMapping("supper_company", SupperCompany.class);
		arp.addMapping("store_company", "store_id", StoreCompany.class);
		
		//采购信息
		arp.addMapping("bbs_procurement", Procurement.class);
		arp.addMapping("bbs_procurement_collect", ProcurementCollect.class);
		arp.addMapping("bbs_procurement_complain", ProcurementComplain.class);
		arp.addMapping("bbs_industry_category", IndustryCategory.class);
		arp.addMapping("bbs_project", Project.class);
		
		//招聘信息
		arp.addMapping("bbs_job", Job.class);
		arp.addMapping("bbs_job_collect", JobCollect.class);
		arp.addMapping("bbs_job_complain", JobComplain.class);
		
		//智囊团
//		arp.addMapping("bbs_expert_panel", Expert.class);
		
		//活动信息
		arp.addMapping("activity", Activity.class);
		arp.addMapping("activity_complain", ActivityComplain.class);
		//商品
		arp.addMapping("store_product_info","product_id", Product.class);
		
		//活动信息
		arp.addMapping("member_news", News.class);
		
		//关键词推送
		arp.addMapping("push_record", PushRecord.class);
		arp.addMapping("push_user", PushUser.class);
		arp.addMapping("user_push_account", UserPushAccount.class);
		arp.addMapping("push_num", PushNum.class);
		
		arp.addMapping("user_tag", UserTag.class);
		
		arp.addMapping("area", Area.class);
		
		arp.addMapping("commerce", Commerce.class);
		arp.addMapping("commerce_news", CommerceNews.class);
		
		arp.addMapping("account", Account.class);
		arp.addMapping("login", Login.class);
		arp.addMapping("login_history", LoginHistory.class);
		
		arp.addMapping("app_superman", AppSuperman.class);
		
		arp.addMapping("draw_detail", DrawDetail.class);
		arp.addMapping("sp_commission", Commission.class);
		arp.addMapping("sp_commission_detail", CommissionDetail.class);
		
		arp.addMapping("store_setting", StoreSetting.class);
	}

	@Override
	public void configRoute(Routes route) 
	{
		route.add("/", IndexAction.class, AppConst.JSP_BASE_VIEW_PATH + "/");
		
		//管理后台路由
		route.add(new AdminRoute());
		
		//API路由
		route.add(new ApiRoute());

	}
}
